﻿@using eCollabro.Client.Models.Content;
@using eCollabro.Client.Models.Core;
@using eCollabro.Web.Base;
@using eCollabro.Common;
@model ImageModel
@if (!Request.IsAjaxRequest())
{
    @Scripts.Render("~/bundles/imagegallery")
}
@{
    List<PermissionEnum> userPermissions = (List<PermissionEnum>)ViewBag.UserPermissions;
    bool canEdit = userPermissions.Contains(PermissionEnum.EditContent);
    bool canDelete = userPermissions.Contains(PermissionEnum.DeleteContent);
    bool canAdd = userPermissions.Contains(PermissionEnum.AddContent);

    List<PageButton> pageButtons = new List<PageButton>();
    pageButtons.Add(new PageButton { Id = "btnImages", ButtonText = "Images", HideOnFooter = true, CssClass = "btn btn-success", Icon = "th-list", Method = "openImages(" + Model.ImageGalleryId + ")" });
    if ((canEdit && !Model.ImageId.Equals(0)) || (canAdd && Model.ImageId.Equals(0)))
    {
        pageButtons.Add(new PageButton { Id = "btnSave", ButtonText = "Save", CssClass = "btn btn-primary", Icon = "floppy-disk", Method = "saveImage()" });
    }
}
<div id="divImage" ng-controller="imageController" ng-init="loadImage(@Model.ImageId,@Model.ImageGalleryId)">
    @Html.Partial("_PageHeader", new PageHeaderModel { ViewId = "Image", PageTitle = " Image - Add/Edit", ValidateForm = true,PageButtons=pageButtons })
    @using (Html.BeginForm("ManageImage", "ImageGallery", FormMethod.Post, new { role = "form", id = "frmImage", @class = "form-horizontal", enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        <div class="form-group">
            @Html.LabelFor(m => m.ImageTitle, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                @Html.TextBoxFor(m => m.ImageTitle, new { ng_model = "image.ImageTitle", @class = "form-control", maxlength = "50" })
                @Html.ValidationMessageFor(m => m.ImageTitle)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.ImageDescription, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                @Html.TextAreaFor(m => m.ImageDescription, new { ng_model = "image.ImageDescription", @class = "form-control", maxlength = "255" })
                @Html.HiddenFor(m => m.ImageId, new { ng_model = "image.ImageId" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.ImageGalleryId, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                <select data-ng-model="selectedImageGallery" ng-options="imageGallery.ImageGalleryName for imageGallery in imageGalleries" class="form-control" ng-change="updateImageGallery()"></select>
            </div>
            @Html.HiddenFor(m => m.ImageGalleryId)
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.ImageFile, new { @class = "col-md-2 control-label" })
            <div class="col-md-5">
                <input type="file" name="file" id="ImageFile" />
                @if (!Model.ImageId.Equals(0))
                {
                    <img src="/content/ImageGallery/ImageThumbnail/@Model.ImageId" alt="{{Image.ImageTitle}}" />
                }
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-2"></div>
            <div class="col-md-5">
                <div class="checkbox">
                    @Html.CheckBoxFor(m => m.IsActive, new { ng_model = "image.IsActive" })
                    @Html.LabelFor(m => m.IsActive)
                </div>
            </div>
        </div>
        <div class="col-md-1"></div>
        <div class="col-md-11">
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">Content Setting</div>
                <div class="panel-body">
                    <div class="form-group" style="padding-left:5px">
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsAnomynousAccess, new { ng_model = "image.IsAnomynousAccess" }) @Html.LabelFor(m => m.IsAnomynousAccess)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsCommentsAllowed, new { ng_model = "image.IsCommentsAllowed" }) @Html.LabelFor(m => m.IsCommentsAllowed)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsLikeAllowed, new { ng_model = "image.IsLikeAllowed" }) @Html.LabelFor(m => m.IsLikeAllowed)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsRatingAllowed, new { ng_model = "image.IsRatingAllowed" }) @Html.LabelFor(m => m.IsRatingAllowed)
                        </label>
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(m => m.IsVotingAllowed, new { ng_model = "image.IsVotingAllowed" }) @Html.LabelFor(m => m.IsVotingAllowed)
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            @Html.Partial("_PageFooter", new PageFooterModel
                {
                    PageButtons = pageButtons
                })
        </div>
    }
</div>
